package com.example.app2

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.navigation.fragment.findNavController

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
 * A simple [Fragment] subclass.
 * Use the [ThreeFragment.newInstance] factory method to
 * create an instance of this fragment.
 */
class ThreeFragment : Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        Log.e("ThreeFragment","onCreateView")
        return inflater.inflate(R.layout.fragment_three, container, false)
    }
//    https://www.bilibili.com/video/BV1Ct411g7P1?p=2
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

    //在navigation  xml里面设置
//                app:popUpTo="@id/mainFragment"
    //            app:popUpToInclusive="true"     //这样就会清空回退栈里面的
        view.findViewById<Button>(R.id.button3).setOnClickListener {
            findNavController().navigate(R.id.action_threeFragment_to_mainFragment)
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.e("ThreeFragment", "onDestroy")
    }

}